@extends('admin.layout.layout')
@section('content')
<style type="text/css">
  .delete{cursor:pointer;}
</style>
<div class="col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
            敏感词替换
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
          <div class="dataTable_wrapper">
            <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
              <div class="row">
                <div class="col-sm-12">
                  <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
                    <thead>
                      <tr role="row">
                        <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">ID</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending">需要替换的词</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending">替换的词</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending">操作</th></tr>
                    </thead>
                    <tbody>
                    @foreach($sensitive as $k=>$v)
                      <tr class="gradeA odd" role="row">
                        <td class="sorting_1 sid">{{$v->id}}</td>
                        <td class="center">{{$v->keyword}}</td>
                        <td class="center">{{$v->replace}}</td>
                        <td class="center">
                          <a class="fa fa-trash-o delete">删除</a>
                        </td>
                      </tr>
                    @endforeach
                    </tbody>
                  </table>
                  {!! $sensitive->render() !!}
                </div>
              </div>
              </div>
            </div>
          </div>
  <!-- /.table-responsive -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>

@endsection
@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
  headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});
  $('.delete').click(function(){
    var dd = $(this);
    if(confirm('你确定删除吗?')){
      var id=dd.parents('tr').find('.sid').html();
      // alert(id);
      // 发送ajax
      $.post('/admin/sensitive/delete',{id:id},function(data){
        if(data == 2){
          dd.parents('tr').remove();
          message('success','删除成功');
        }else{
          message('error','删除失败');
        }
      })
    }
  })
  // 封装函数显示信息
  function message(er,m){
    if(er == 'success'){
      $("#messagesuccess").find("span").text(m);
      $("#messagesuccess").show();

    }else{
      $("#messagedanger").find("span").text(m);
      $("#messagedanger").show();
    }
  }
</script>
@endsection